Layout & input/output Components
View
- React의 div태그와 비슷한 역할을 하는 컨테이너 컴포넌트
- 여러 개의 요소를 감싸고 스타일을 적용할 때 사용
- 스타일 적용 시 flexbox 레이아웃을 지원
App.tsx
import { StatusBar } from "expo-status-bar";
import { StyleSheet, Text, View } from "react-native";
export default function App() {
return (
<View style={{ flex: 1, backgroundColor: "red" }}>
<View style={{ width: 200, height: 200, backgroundColor: "blue" }}>
<View style={{ width: 100, height: 100, backgroundColor: "orange" }} />
</View>
</View>
);
}
note
React Native의 View를 이용하여 전체 화면을 표현하기 위해서는 style에 flex: 1
을 이용하면 된다.
React Native의 기본 루트 컨테이너인 ReactRootView
가 flex
이기 때문에 적용 가능.
Text
- 텍스트를 표시하는 컴포넌트
- View 내부에서 사용 가능하며, 여러 줄로 작성 가능
App.tsx
import { StatusBar } from "expo-status-bar";
import { StyleSheet, Text, View } from "react-native";
export default function App() {
return (
<View style={{ flex: 1 }}>
<Text style={{ fontSize: 20, color: "blue" }}>React Native Text</Text>
<Text>가나다라마바사 {"\n"} 아자차카타파하</Text>
</View>
);
}
note
React Native에서 Text안 글들을 띄워쓰기 위해서는 {"\n"}
을 사용하면 된다.
Text 속성 정리
속성명 | 타입 | 기본값 |
---|